#include "../../../common/mysql.hpp"
#include "../../../odb/user.hxx"
#include "user-odb.hxx"
#include <gflags/gflags.h>
#include "../../../common/mysql_user.hpp"

DEFINE_bool(run_mode,false,"程序的运行模式，false： 调试 true： 发布");
DEFINE_string(log_file,"","发布模式下，向文件中输出，如果是调试模式下，模式是stdout");
DEFINE_int32(log_level,0,"发布模式下，用于指定的日志输出等级");


DEFINE_string(host,"127.0.0.1","这是mysql的地址");
DEFINE_int32(port,0,"这是mysql的端口");
DEFINE_string(db,"TestDB","数据库默认的库");
DEFINE_string(user,"root","这是用户名");
DEFINE_string(passward,"123456","这是密码");
DEFINE_string(cset,"utf8","这是mysql客户端字符集");
DEFINE_int32(max_pool,3,"这是mysql连接池最大连接数量");

void test_insert(UserTable& user) 
{
    auto user1 = std::make_shared<User>("uid1","昵称1","11111111");
    user.insert(user1);

    auto user2 = std::make_shared<User>("uid2","昵称2","2222222");
    user.insert(user2);
}

void test_update_by_id(UserTable& user_tb)
{
    auto user1 = user_tb.select_by_id("uid1");
//    std::cout << "查询成功" << *user1->nickname() <<  std::endl;
    user1->set_description("这是一个签名");
    user_tb.update(user1);
}

void test_updatee_by_phone(UserTable& user_tb)
{
    auto user1 = user_tb.select_by_phone("4444");
    std::cout << user1->nickname() << std::endl;
    user1->set_avatar_id("这是头像ID");
    user_tb.update(user1);
}

void test_update_by_nickname(UserTable& user_tb)
{
    auto user1 = user_tb.select_by_nickname("昵称1");
    std::cout << user1->nickname() << std::endl;
    user1->set_phone("4444");
    user_tb.update(user1);
}

void test_multi_users(UserTable& user_tb)
{
    std::vector<std::string> id_list = {"uid1","uid2"};
    auto res = user_tb.select_multi_users(id_list);
    for(auto e : res) {
        std::cout << e.nickname() << std::endl;
    }
}

int main(int argc,char* argv[])
{
    google::ParseCommandLineFlags(&argc,&argv,true);
    init_logger(FLAGS_run_mode,FLAGS_log_file,FLAGS_log_level);

    auto db = ODBFactory::create(FLAGS_user,FLAGS_passward,FLAGS_db,FLAGS_host,FLAGS_cset,0,1);
    UserTable user(db);

//    test_insert(user);
//    test_update_by_id(user);
//    test_update_by_nickname(user);
//    test_updatee_by_phone(user);
    test_multi_users(user);
    return 0;   
}